package com.sdkj.service.car;

import java.util.List;

import javax.annotation.Resource;

import org.activiti.engine.IdentityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sdkj.activiti.util.ActivitiUtils;
import com.sdkj.dao.DaoSupport;
import com.sdkj.entity.Page;
import com.sdkj.service.activiti.ActTaskService;
import com.sdkj.util.PageData;


@Service("carapplyService")
public class CarApplyService {

	@Resource(name = "daoSupport")
	private DaoSupport dao;
	
	@Autowired
	private IdentityService identityService;
	
	@Autowired
	private ActTaskService actTaskService;
	
	/*
	* 新增
	*/
	public void applyAdd(PageData pd)throws Exception{
		String user_id = pd.getString("user_id");
		identityService.setAuthenticatedUserId(user_id);
		String process_instance_id = actTaskService.startProcess(user_id,ActivitiUtils.PD_CAR_APPLY[0],ActivitiUtils.PD_CAR_APPLY[1],pd.getString("apply_id"),pd.getString("apply_event"));
		pd.put("process_instance_id", process_instance_id);
		dao.save("CarApplyMapper.applyAdd", pd);
	}
	
	/*
	* 删除
	*/
	public void delete(PageData pd)throws Exception{
		dao.delete("CarApplyMapper.delete", pd);
	}
	
	/*
	* 修改
	*/
	public void adminEdit(PageData pd)throws Exception{
		dao.update("CarApplyMapper.adminEdit", pd);
	}
	
	/*
	*列表
	*/
	public List<PageData> list(Page page)throws Exception{
		return (List<PageData>)dao.findForList("CarApplyMapper.datalistPage", page);
	}
	
	/*
	*列表(全部)
	*/
	public List<PageData> listAll(PageData pd)throws Exception{
		return (List<PageData>)dao.findForList("CarApplyMapper.listAll", pd);
	}
	
	/*
	* 通过id获取数据
	*/
	public PageData findById(PageData pd)throws Exception{
		return (PageData)dao.findForObject("CarApplyMapper.findById", pd);
	}
	
	public PageData findByIdAll(PageData pd)throws Exception{
		return (PageData)dao.findForObject("CarApplyMapper.findByIdAll", pd);
	}
	
	public PageData findByProcInsId(PageData pd)throws Exception{
		return (PageData)dao.findForObject("CarApplyMapper.findByProcInsId", pd);
	}
	
	/*
	* 批量删除
	*/
	public void deleteAll(String[] ArrayDATA_IDS)throws Exception{
		dao.delete("CarApplyMapper.deleteAll", ArrayDATA_IDS);
	}
	
}

